package com.software.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.software.lease.model.entity.PaymentType;
import com.software.lease.web.admin.service.PaymentTypeService;
import com.software.lease.web.admin.mapper.PaymentTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
* @author liubo
* @description 针对表【payment_type(支付方式表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class PaymentTypeServiceImpl extends ServiceImpl<PaymentTypeMapper, PaymentType>
    implements PaymentTypeService{

    @Autowired
    private PaymentTypeMapper paymentTypeMapper;

    /**
     * 查询全部的支付方式
     * @return
     */
    @Override
    public List<PaymentType> listPaymentType() {
        List<PaymentType> list = paymentTypeMapper.selectAll();
        return list;
    }

    /**
     * 保存支付方式
     * @param paymentType
     */
    @Override
    public void saveOrUpdatePaymentType(PaymentType paymentType) {
        List<PaymentType> list = paymentTypeMapper.selectAll();
        for(PaymentType type : list){
            if(type.equals(paymentType)){
                return;
            }
        }
        Timestamp createTime = new Timestamp(System.currentTimeMillis());
        paymentType.setCreateTime(createTime);
        paymentTypeMapper.savePaymentType(paymentType);
    }

}




